home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Ian & Stuart's Australian Mac 1993 September
/
September 93.iso
/
Archives
/
Utilities
/
Disk & File
/
Disk
/
CDRom
/
DontShareIt Lite
/
DontShareIt Lite.c
< prev
next >
Wrap
C/C++ Source or Header
|
1993-06-17
|
8KB
|
273 lines
/* Don’tShareIt... Lite */
/* by Jim Luther */
#include "DontShareIt Lite.h"
/* A4 globals */
Ptr gGetVolInfoLink;
Boolean gProcessMgrAvailable;
long gAttribs;
short gAFPTranslatorRefNum;
Ptr gSetTrapAddrLink;
Boolean gHasRun;
Ptr PatchTrap(short trapWord, short trapType, ProcPtr newAddress)
/* Patches specified A-Trap and returns the old A-Trap routine address */
{
long oldAddress;
newAddress = StripAddress((Ptr)newAddress);
oldAddress = NGetTrapAddress(trapWord,trapType);
NSetTrapAddress((long)newAddress,trapWord,trapType);
return (Ptr)oldAddress;
}
Boolean IsTargetApp(void)
/* See if the current process is File Sharing, AppleShare, or AppleShare Admin. */
/* Call GetProcessInformation and check the creator type returned against */
/* 'hhgg' (File Sharing), 'hhge' (AppleShare), and 'admn' (AppleShare Admin). */
{
OSErr result;
ProcessSerialNumber currentPSN;
ProcessInfoRec info;
short theCount;
/* If Process Manager wasn't available last time we looked, see if it is now. */
if (!gProcessMgrAvailable) {
gProcessMgrAvailable = ((Gestalt(gestaltOSAttr, &gAttribs) == noErr) &&
(gAttribs & (1 << gestaltLaunchControl)));
/* If Process Manager still isn't available, then the target processes aren't. */
if (!gProcessMgrAvailable)
return (false);
}
/* Do a quick check of the current application for the Finder since it polls
** GetVolInfo very heavily. This saves a call to GetProcessInformation which
** probably reduces any performance hit this patch makes on the system.
** If someone were to rename one of the apps I'm checking for to the
** FinderName, this wouldn't work. I hope that doesn't happen... */
if (CurApName[0] == FinderName[0]) {
theCount = 1;
while (theCount <= CurApName[0]) {
if (CurApName[theCount] != FinderName[theCount])
break;
theCount++;
}
if (theCount == CurApName[0]+1)
return (false); /* CurApName == FinderName */
}
/* Get the current process' creator type with GetProcessInformation */
currentPSN.highLongOfPSN = 0;
currentPSN.lowLongOfPSN = kCurrentProcess;
info.processInfoLength = sizeof(ProcessInfoRec);
info.processName = nil; /* we don't want the process name */
info.processAppSpec = nil; /* we don't want the process file location */
result = GetProcessInformation(¤tPSN, &info);
if (result == noErr)
/* See if the current process is one of the target processes. */
switch (info.processSignature) {
case kFileSharingCreator:
case kAppleShareCreator:
case kASAdminCreator:
return (true);
break;
}
return (false);
}
OSErr PGetVolInfo(void)
/* Here's the patch to _GetVolInfo */
{
HParmBlkPtr pBlock; /* pointer to the parameter block */
short trapWord; /* the trapword */
Ptr nextLink; /* the GetVolInfo routine before we patched */
Boolean myVolNameBuffer; /* did we supply the volume name buffer? */
OSErr result; /* result to return to caller */
/* Get register values before they're blown away */
asm {
move.w d1,trapWord ; get the trapword from D1
move.l a0,pBlock ; get the parameter block pointer from A0
}
SetUpA4(); /* set up the A4 world */
nextLink = gGetVolInfoLink; /* get the next link from gGetVolInfoLink */
if (((trapWord & kAsyncBit) != 0) || /* if the call is async or */
((trapWord & kHFSBit) == 0)) /* the call isn't _HGetVInfo */
/* jump to the next link (head patch only) */
asm {
move.w trapWord,d1 ; restore the trapword to D1
move.l pBlock,a0 ; restore the parameter block pointer to A0
move.l nextLink,a1 ; get nextLink
move.l (sp)+,a4 ; do what RestoreA4 normally does
unlk a6 ; unlink A6
move.l a1,-(sp) ; put nextLink on the stack and
rts ; return to it
}
/* This is a synchronous _HGetVInfo call */
/* go ahead and make the call and we'll do more in the tail patch. */
asm {
move.w trapWord,d1 ; restore the trapword to D1
move.l pBlock,a0 ; restore the parameter block pointer to A0
move.l nextLink,a1 ; get nextLink
jsr (a1) ; and call it...
}
/* If errors, then do nothing */
if (pBlock->volumeParam.ioResult == noErr) {
/* We know that we can skip any volumed owned by the .Sony driver ($fffb)
or drives owned by the .AFPTranslator driver because the file server
already ignores them. */
if ((pBlock->volumeParam.ioVDRefNum != SonyRefNum) &&
(pBlock->volumeParam.ioVDRefNum != gAFPTranslatorRefNum)) {
/* Check for the target applications */
if (IsTargetApp()) {
/* Is this volume owned by Audio CD Access? */
if (pBlock->volumeParam.ioVFSID == 0x4A48) {
/* Yes, now we'll make this volume unusable by the file server. */
/* The only ways to do that are to make ioVDRefNum == 0xfffb (.Sony), */
/* make ioVFSID == the file system ID used by the AppleShare workstation, */
/* or to make ioVSigWord != 0x4244 (HFS volume). */
/* I'll simply clear ioVSigWord which should do the trick nicely. */
pBlock->volumeParam.ioVSigWord = 0;
}
}
}
}
RestoreA4();
return (pBlock->volumeParam.ioResult);
}
short NumToolboxTraps(void)
{
if (NGetTrapAddress(_InitGraf, ToolTrap) == NGetTrapAddress(0xAA6E, ToolTrap))
return (0x200);
else
return (0x400);
}
TrapType GetTrapType(short theTrap)
{
if ((theTrap & 0x0800) > 0)
return (ToolTrap);
else
return (OSTrap);
}
Boolean TrapAvailable(short theTrap)
{
TrapType tType;
tType = GetTrapType(theTrap);
if (tType == ToolTrap) {
theTrap = theTrap & 0x07ff;
if (theTrap >= NumToolboxTraps())
theTrap = _Unimplemented;
}
return (NGetTrapAddress(theTrap, tType) != NGetTrapAddress(_Unimplemented, ToolTrap));
}
void PatchGetVolInfo(void)
{
/* Find out if the process manager is available (it shouldn't be yet) */
gProcessMgrAvailable = ((Gestalt(gestaltOSAttr, &gAttribs) == noErr) &&
(gAttribs & (1 << gestaltLaunchControl)));
/* Get the .AFPTranslator driver's reference number */
if (OpenDriver(kAFPTranslatorName, &gAFPTranslatorRefNum) != noErr)
gAFPTranslatorRefNum = 0;
/* Patch _GetVolInfo (A-Trap $A007) */
gGetVolInfoLink = PatchTrap(_GetVolInfo, OSTrap, PGetVolInfo);
}
void SetTrapAddrPatch(void)
{
Ptr nextLink;
short trapWord;
short callerTrapWord; // the trap word used to make this call is in d1
asm {
movem.l a0-a5/d0-d7,-(sp)
move.w d0,trapWord
move.w d1,callerTrapWord
}
SetUpA4();
nextLink = gSetTrapAddrLink;
if (!gHasRun &&
(trapWord == _ServerDispatch) &&
((callerTrapWord & kTrapTypeMask) == kOSTrapType)) {
// _ServerDispatch trap is being installed
gHasRun = true;
PatchGetVolInfo();
}
asm{
move.l (sp)+,a4 ; same as RestoreA4()
movem.l (sp)+,a0-a5/d0-d7
move.l nextLink,a1
unlk a6
jmp (a1)
}
}
void main(void)
{
Ptr codePtr;
Handle codeHndl;
asm {
move.l a0,codePtr ; get point to our code
}
/* Register A0 contains pointer to my code resource */
RememberA0(); /* save A0 where we can get to it later */
SetUpA4(); /* and set up the A4 world */
codeHndl = RecoverHandle(codePtr); /* get handle to our code */
DetachResource(codeHndl); /* and detach our code resource */
if (TrapAvailable(_ServerDispatch)) {
/* install _GetVolInfo patch now */
PatchGetVolInfo();
}
else {
/* Install patch to SetTrapAddress when _ServerDispatch is installed. */
/* That's where the _GetVolInfo patch will be installed if the AppleShare */
/* of File Sharing server software is installed. */
gHasRun = false; /* The SetTrapAddress patch for _ServerDispatch */
/* hasn't been executed. */
gSetTrapAddrLink = PatchTrap(_SetTrapAddress, OSTrap, SetTrapAddrPatch);
}
RestoreA4();
}